package com.benyi.util;

 

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

public class Net {
	
    public static void main(String[] args) throws Exception {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        int n=0;
        while(networkInterfaces.hasMoreElements()) {
            NetworkInterface interface1 = networkInterfaces.nextElement(); 
            if (interface1.getParent() == null && 
            		interface1.getInetAddresses() != null && 
            		interface1.getHardwareAddress() != null){
            	n++;
                Enumeration<InetAddress> inetAddrs = interface1.getInetAddresses();
                
                System.out.print("["+n+"]网卡名称：");
                System.out.println(interface1.getName() + " " + interface1.getDisplayName());
                
                System.out.print("MAC：");
                byte[] btMac = interface1.getHardwareAddress();
                for (int i = 0; i < btMac.length; i++) {
                    System.out.print(Integer.toHexString(btMac[i] & 0xff).toUpperCase());
                    if(i < btMac.length - 1) System.out.print(":");
                }
                System.out.println();
                
                System.out.println("网卡IP：");
                while (inetAddrs.hasMoreElements())
                    System.out.println(inetAddrs.nextElement());
                System.out.println();
                System.out.println();
            }
        }
    }
}